package com.sdry.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sdry.entity.ApprovalEntity;
import com.sdry.entity.approvalManagement.ApprovalDetail;
import com.sdry.entity.approvalManagement.ModelEntity;
import com.sdry.mapper.ApprovalInitiateMapper;
import com.sdry.service.ApprovalInitiateService;

@Service
@Transactional
public class ApprovalInitiateServiceImpl implements ApprovalInitiateService {

	@Resource
	private ApprovalInitiateMapper approvalInitiateMapper;
	
	@Override
	public List<ModelEntity> listAllModel() {
		// TODO Auto-generated method stub
		return approvalInitiateMapper.listAllModel();
	}

	@Override
	public ModelEntity findModelByID(long mId) {
		// TODO Auto-generated method stub
		return approvalInitiateMapper.findModelByID(mId);
	}

	@Override
	public Integer saveApprovalDetail(ApprovalDetail approvalDetail, String[] modelValue) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		String mValues = "";
		for (int i = 0; i < modelValue.length; i++) {
			if (i == modelValue.length-1) {
				mValues = mValues + modelValue[i];
			} else {
				mValues = mValues + modelValue[i] + ",";
			}
		}
		approvalDetail.setmValues(mValues);
		isSuccess = approvalInitiateMapper.saveApprovalDetail(approvalDetail);
		return isSuccess;
	}

	@Override
	public ApprovalDetail findDetailByID(long approvalId) {
		// TODO Auto-generated method stub
		return approvalInitiateMapper.findDetailByID(approvalId);
	}

	@Override
	public Integer updateApproval(ApprovalEntity approvalEntity) {
		// TODO Auto-generated method stub
		return approvalInitiateMapper.updateApproval(approvalEntity);
	}

}
